import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../utils/utils.dart';

/// 缓存图片
Widget netImageCached(
  String url, {
  double width = 48,
  double height = 48,
  double radius = 6,
  EdgeInsetsGeometry? margin,
  bool showProgress = true,
  BoxFit? fit = BoxFit.contain,
  bool showError = true,
}) {
  return CachedNetworkImage(
    imageUrl: url,
    imageBuilder: (context, imageProvider) => Container(
      height: height,
      width: width,
      margin: margin,
      decoration: BoxDecoration(
        borderRadius: radius.radius,
        image: DecorationImage(
          image: imageProvider,
          fit: fit,
          // colorFilter: const ColorFilter.mode(Colors.blue, BlendMode.colorBurn),
        ),
      ),
    ),
    placeholder: (context, url) {
      return showProgress
          ? Container(
              height: height,
              width: width,
              alignment: Alignment.center,
              padding: EdgeInsets.all(4.w),
              child: const CircularProgressIndicator(),
            )
          : SizedBox(height: height, width: width);
    },
    errorWidget: (context, url, error) => SizedBox(
      width: width,
      height: height,
      child: const Icon(Icons.error),
    ),
  );
}
